//
//  OEAddCardViewController.m
//  OneEightyNine
//
//  Created by Mac on 2019/3/7.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OEDepositReturnViewController.h"
#import "OERetunSuccessViewController.h"
@interface OEDepositReturnViewController ()
@property(nonatomic, strong) UITextField                     *moneyTextFiled;/**<  */
@end

@implementation OEDepositReturnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Return Deposit";
    [self configSubView];
    // Do any additional setup after loading the view.
}
#pragma mark --subView
- (void)configSubView{
    
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    self.tableView.backgroundColor = OE_GrayColor;
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth - 30, 40)
                                                     text:@"Please input Your return money"
                                                textColor:SecendTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [footer addSubview:titleLable];
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, UIScreenWidth - 0, 50)];
    whiteView.layer.cornerRadius = 0;
    whiteView.clipsToBounds = YES;
    whiteView.backgroundColor = UIColor.whiteColor;
    [footer addSubview:whiteView];
    
    
    
    self.moneyTextFiled = [TMUtils textFiledWithLeftTitle:@"MONEY" placeHolader:@"" rightView:nil];
    self.moneyTextFiled.width = whiteView.width;
    self.moneyTextFiled.leftView.width = 80;
    [self.moneyTextFiled st_showBottomLine];
    self.moneyTextFiled.keyboardType = UIKeyboardTypeNumberPad;
    [whiteView addSubview:self.moneyTextFiled];
    
    
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(30, whiteView.bottom + 20, UIScreenWidth - 60 , 44)
                                                        title:@"COMPLETE"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:18
                                                 cornerRadius:22
                                              backgroundColor:OE_LIMITE_COLOR
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedNextButton];
    }];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    
    footer.height = confimButton.bottom;
    self.tableView.tableFooterView = footer;
}
#pragma mark --Action Method

- (void)onSelctedNextButton{
    if (!self.moneyTextFiled.text.length) {
        [SVProgressHUD showInfoWithStatus:@"Please input Money"];
        return;
    }
    //请求
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    if (self.moneyTextFiled.text.length) {
        [paramDic setObject:self.moneyTextFiled.text forKey:@"money"];
    }
    if (self.bank_id.length) {
        [paramDic setObject:self.bank_id forKey:@"bank_id"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=User&a=cashApply"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 OERetunSuccessViewController * vc = OERetunSuccessViewController.new;
                                                 vc.money = self.moneyTextFiled.text;
                                                 [self.navigationController pushViewController:vc animated:YES];
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 //                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
}
@end
